package com.bw.z.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class DBManager {

    private static String USER = "user.db";
    private DaoMaster daoMaster;
    private DaoSession daoSession;

    private Context context;
    private SQLiteDatabase.CursorFactory factory;

    public DBManager(Context context) {
        this.context = context;
    }

    public DaoSession getDaoSession() {
        if (daoMaster == null) {
            DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(context, USER);
            daoMaster = new DaoMaster(devOpenHelper.getWritableDb());
        }
        if (daoSession == null) {
            daoSession = daoMaster.newSession();
        }
        return daoSession;
    }

    private static DBManager manager;

    public static DBManager getInstance(Context context) {
        if (manager == null)
            manager = new DBManager(context);
        return manager;
    }

}
